package com.rabbitMQ.producer;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer_WorkQueues {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.23.129"); // 设置连接 ip 默认 localhost
        factory.setPort(5672);  // 设置连接端口 默认 5672
        factory.setVirtualHost("/root"); // 虚拟机 我们这里使用 /root
        factory.setUsername("root");    // 拥有权限的用户
        factory.setPassword("root");    // 拥有权限的用户密码
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare("work_queues", true, false, false, null);
        for (int i = 0; i < 9; i++) {
            channel.basicPublish("", "work_queues", null, ("Hello queues "+i).getBytes());
        }
        channel.close();
        connection.close();
    }
}
